package com.woniu.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.controller.form.AddStationFrom;
import com.woniu.controller.form.AddStationRefuseJunkForm;
import com.woniu.controller.form.DelStationRefuseJunkForm;
import com.woniu.model.Result;
import com.woniu.model.StationRefuseJunk;
import com.woniu.service.StationRefuseJunkService;
import com.woniu.service.param.AddStationParam;
import com.woniu.service.param.AddStationRefuseJunkParam;
import com.woniu.service.param.DelStationRefuseJunkParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author eason
 * @since 2024年05月25日
 */
@RestController
@RequestMapping("/stationRefuseJunk")
@Api(tags = "站点垃圾种类黑名单接口")
public class StationRefuseJunkController {
    @Resource
    private StationRefuseJunkService stationRefuseJunkService;

    /**
     * 新增站点垃圾种类黑名单
     */
    @PostMapping("/add.api")
    @ApiOperation("新增站点垃圾种类黑名单")
    public Result<?> add(AddStationRefuseJunkForm form) throws Exception {

        stationRefuseJunkService.add(BeanUtil.toBean(form, AddStationRefuseJunkParam.class));
        return Result.newInstance(null).setCode(200).setData(null).setMessage("新增站点垃圾种类黑名单成功!");
    }

    /**
     * 删除站点垃圾种类黑名单
     */
    @PostMapping("/del.api")
    @ApiOperation("站点删除垃圾种类黑名单")
    public Result<?> del(DelStationRefuseJunkForm form) throws Exception {

        stationRefuseJunkService.del(BeanUtil.toBean(form, DelStationRefuseJunkParam.class));
        return Result.newInstance(null).setCode(200).setData(null).setMessage("删除站点垃圾种类黑名单成功!");
    }

    /**
     * 根据站点id查看垃圾种类黑名单list
     */
    @GetMapping("/loadByStationId/{id}")
    @ApiOperation("根据站点id查看垃圾种类黑名单list")
    public Result<?> loadByStationId(@PathVariable Integer id) throws Exception {
        List<StationRefuseJunk> stationRefuseJunks =stationRefuseJunkService.loadByStationId(id);
        return Result.newListInstance(StationRefuseJunk.class).setCode(200).setData(stationRefuseJunks).setMessage("根据站点id查看垃圾种类黑名单成功!");
    }

}

